package com.phamloc.shootingchicken.objects;

import org.andengine.entity.sprite.ButtonSprite;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.TextOptions;
import org.andengine.opengl.font.BitmapFont;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.util.adt.align.HorizontalAlign;

import com.phamloc.shootingchicken.extra.AudioPlayer;
public class ButtonSpriteWithText extends ButtonSprite {

    private static final float HALF = 2f;
    private final Text mText;

    public ButtonSpriteWithText(final float pX, final float pY, final ITiledTextureRegion pTextureRegion,

            final VertexBufferObjectManager pVertexBufferObjectManager, final String pText,

            final BitmapFont pFont, final AudioPlayer pAudioPlayer) {

        super(pX, pY, pTextureRegion.getTextureRegion(0),pTextureRegion.getTextureRegion(1),pTextureRegion.getTextureRegion(2) ,pVertexBufferObjectManager);

        mText = new Text(pX, pX, pFont, pText, new TextOptions(HorizontalAlign.CENTER),

                pVertexBufferObjectManager);
        final float hightTxt = mText.getHeight();

        final float hightBtn = pTextureRegion.getTextureRegion(0).getHeight();

 

        final float widthTxt = mText.getWidth();

        final float widtBtn = pTextureRegion.getTextureRegion(0).getWidth();


        final float positionX = widtBtn / HALF - widthTxt / HALF;

        final float positionY = hightBtn / HALF - hightTxt/HALF;

 

        mText.setX(positionX);

        mText.setY(positionY);

        attachChild(mText);

    }

 


    public void setBlendFunction(final int pBlendFunctionSource, final int pBlendFunctionDestination) {

 

        mText.setBlendFunction(pBlendFunctionSource, pBlendFunctionDestination);

    }


    public void setAlpha(final float pAlpha) {

        super.setAlpha(pAlpha);

        mText.setAlpha(pAlpha);
}


    public void setColor(final float pRed, final float pGreen, final float pBlue){

        mText.setColor(pRed, pGreen, pBlue);

    }

}
